package com.manager.opecourse;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;

public class OptCourseController extends Controller {
	private static final int PAGE_SIZE = 10;
	public void index() {
		int sid = getParaToInt(1);
		setAttr("optcoursePage", OptCourse.me.paginate(sid, getParaToInt(0, 1), PAGE_SIZE));
		setAttr("sid", sid);
		render("optcourse.html");
	}

	public void add() {
		int sid = getParaToInt(0);
		setAttr("tlist",
				Db.find("select id, course_name from course where id not in (select cid from opt_course where sid = "
						+ sid + ");"));
		setAttr("sid", sid);
		// redirect("/optcourse/" + sid);
	}

	public void save() {
		getModel(OptCourse.class).save();
		redirect("/optcourse/1-" + getParaToInt(0));
	}

	public void delete() {
		getModel(OptCourse.class).deleteById(getParaToInt(0));
		redirect("/optcourse/1-" + getParaToInt(1));
	}
}
